package problems.daily;

/**
 * @author dubulingbo, 2023-04-12 9:08.
 */
public class DT1147 {
    public int longestDecomposition(String text) {
        int rm = text.length();
        int lm = -1;
        int l = 0;
        int r = text.length() - 1;
        int cnt = 0;
        while (l < r) {
            if (text.substring(lm + 1, l + 1).equals(text.substring(r, rm))) {
                cnt += 2;
                lm = l;
                rm = r;
            }
            ++l;
            --r;
        }

        if (lm + 1 < rm) ++cnt;

        return cnt;
    }
}
